

<template tag="以下文档内容为hycli自动生成">
  <el-dialog
    v-model="conf.visible"
    
    :title="title"
    :width="conf.width"
    draggable
    align-center="true"
    :close-on-click-modal="false"
  >
<el-form :model="form"  ref="form" :rules="rules_aaatu">
    <el-row>
    <el-col :span="12">
    <!-- {"index":64,"raw":"sys_id","name":"sys_id","cname":"SysId","type":{"raw":"number(10)","name":"number","len":10,"dlen":0},"defValue":"","allowNull":false,"constraints":["UNQ(unq_sso_rolem_srmenu,2)","q","l","le","v","c","u","sl(system_info)"],"desc":{"raw":"系统","name":"系统"}} -->
     <!--系统 下拉控件 -->
    <el-form-item prop="sys_id" label="系统" label-width="100px" label-position="right">
      <el-select   v-model="form.sys_id" style="width: 100%" filterable clearable
        placeholder="请选择系统" >
        <el-option v-for="item in sys_idList" :key="item.value" :label="item.name" :value="item.value" />
      </el-select>
    </el-form-item>
    </el-col>
    <el-col :span="24">
    <!-- {"index":67,"raw":"menu_id","name":"menu_id","cname":"MenuId","type":{"raw":"varchar2(2000)","name":"varchar2","len":2000,"dlen":0},"defValue":"","allowNull":true,"constraints":["l","le","v","c","u","sl(system_menu)","tp(tree,c-u,single)","ps(newline)"],"desc":{"raw":"菜单","name":"菜单"}} -->
      <!--菜单 页面树 -->
      <el-form-item  label="菜单" label-width="100px" label-position="right">
        <el-tree ref="tree_aaaud" style="width: 100%;  height:singlepx; overflow:auto"
        show-checkbox  node-key="id" default-expand-all :data="menu_idList"
        :props="{children: 'children', label: 'name'}"/>
     </el-form-item>
    </el-col>
    </el-row>
</el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="hide" icon="close">取消</el-button>
        <el-button type="primary" @click="save" icon="select">提交</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script>
import rtext from "@/views/cmpnts/rtext.vue"
export default {
  components: {
    rtext
},
  data() {
    return {
      conf: {
        visible: false,
        width:"60%",
        uploadPath:this.$theia.env.join("/file/upload"),
      },
      title:"修改角色权限",
rules_aaatu:{
    sys_id:[{required:true,message:"请输入系统",trigger: 'blur'}],
    menu_id:[{required:false,message:"请输入菜单",trigger: 'blur'}],
  },
    form:{
        sys_id:"",
        menu_id:"",
    },
    sys_idList:[],
    menu_idList:[],
    }
  },
  methods: {
    show(form) {
      this.conf.visible = true;
      this.loadEnums_aaatu()
      this.form = Object.assign(form,this.$route.params)
      this.get(form)
    },
      get(form){
        let that = this
        this.conf.loading = true
        let postForm = {}
        postForm.id = form.id
        this.$theia.http.get("/sso/role/menu",postForm).then(res=>{
          that.$refs.tree_aaaud.setCheckedKeys(res.menu_id.split(","))
          that.form = Object.assign(that.form, res)
          let menu_id = that.form.menu_id.split(",")
          that.form.menu_id = menu_id
        //处理枚举重新绑定
          this.loadEnums_aaatu()
          that.conf.loading = false
        }).catch(res=>{
          let code = ((res||{}).response||{}).status||0
          let msg = `角色权限查询失败(${code})`
          that.$notify.error({title: '失败',message:msg ,duration:5000})
        })
    },
    save(){
        this.$refs.form.validate((v=>{
            if(v) this.onSave()
        }))
    },
    onSave(){
      let that = this
        let postForm = Object.assign({},this.form)
        let checkKeys = this.$refs.tree_aaaud.getCheckedKeys()||[]
        let halfKeys = this.$refs.tree_aaaud.getHalfCheckedKeys()||[]
        postForm.menu_id = checkKeys.concat(halfKeys).join(",")
        this.$theia.http.put("/sso/role/menu",postForm).then(res=>{
            that.$notify.success({title: '成功',message: '角色权限保存成功',duration:5000})
            that.hide()
            that.$emit("onsaved")
        }).catch(res=>{
            let code = ((res||{}).response||{}).status||0
            let msg = `角色权限修改失败(${code})`
            that.$notify.error({title: '失败',message: msg,duration:5000})
        })
    },
    hide() {
      this.conf.visible = false;
      this.$refs.form.resetFields();
    },
     onUploadSuccess(response){
    },
    loadEnums_aaatu(){
        //系统
        this.sys_idList = this.$theia.enum.get("system_info","","" ,false,"")
        //菜单
        this.menu_idList = this.$theia.enum.getTree("system_menu","","" ,99)
    },

  },
};
</script>

<style scoped>
.form_item_info{
  margin-left: 4px;
  color:#999;
}
.form_item_info:hover{
  cursor: pointer;
  font-weight: 500;
  color:#333;
}
</style>